package com.aeoj.clientmanagement.enums;

import lombok.Getter;

/**
 * author: ZSM
 * time: 2025-04-16 22:04
 */
@Getter
public enum ResponseCodeEnum {
    // 2xx Success
    SUCCESS(200, "成功"),
    CREATED(201, "创建成功"),
    ACCEPTED(202, "请求已接受"),
    NO_CONTENT(204, "无内容"),

    // 4xx Client Errors
    BAD_REQUEST(400, "请求参数错误"),
    UNAUTHORIZED(401, "未授权"),
    FORBIDDEN(403, "禁止访问"),
    NOT_FOUND(404, "资源不存在"),
    METHOD_NOT_ALLOWED(405, "方法不允许"),
    CONFLICT(409, "资源冲突"),
    TOO_MANY_REQUESTS(429, "请求过多"),

    // 5xx Server Errors
    INTERNAL_SERVER_ERROR(500, "服务器内部错误"),
    NOT_IMPLEMENTED(501, "功能未实现"),
    SERVICE_UNAVAILABLE(503, "服务不可用"),
    GATEWAY_TIMEOUT(504, "网关超时"),

    // Custom Business Codes (建议从1000开始)
    BUSINESS_ERROR(1000, "业务异常"),
    DATA_NOT_EXIST(1001, "数据不存在"),
    DATA_EXISTED(1002, "数据已存在"),
    PARAM_VALID_ERROR(1003, "参数校验失败"),
    REPEAT_SUBMIT(1004, "重复提交"),
    AUTH_FAILED(1005, "认证失败"),
    PERMISSION_DENIED(1006, "权限不足"),
    THIRD_PARTY_ERROR(1007, "第三方服务错误"),
    DATA_ACCESS_ERROR(1008, "数据访问异常");

    private final int code;
    private final String message;

    ResponseCodeEnum(int code, String message) {
        this.code = code;
        this.message = message;
    }

    /**
     * 根据code获取枚举
     */
    public static ResponseCodeEnum getByCode(int code) {
        for (ResponseCodeEnum responseCodeEnum : ResponseCodeEnum.values()) {
            if (responseCodeEnum.getCode() == code) {
                return responseCodeEnum;
            }
        }
        return null;
    }
}
